<!doctype html>
<html><head>
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0" charset ="UTF-8"/>
	<style type='text/css'>
		html { font-family:Helvetica; color:#222; }
		h1 { color:steelblue; font-size:24px; margin-top:24px; }
		button { margin:0 3px 10px; font-size:12px; }
		.logLine { border-bottom:1px solid #ccc; padding:4px 2px; font-family:courier; font-size:11px; }
	</style>
</head><body>
	<h1>WebViewJavascriptBridge Demo</h1>
	

	<script type="text/javascript">
        
    var js;
 	/*这段代码是固定的，必须要放到js中*/
	function setupWebViewJavascriptBridge(callback) {
		if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
		if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
		window.WVJBCallbacks = [callback];
		var WVJBIframe = document.createElement('iframe');
		WVJBIframe.style.display = 'none';
		WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
		document.documentElement.appendChild(WVJBIframe);
		setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
	}
	  /*与OC交互的所有JS方法都要放在此处注册，才能调用通过JS调用OC或者让OC调用这里的JS*/
	setupWebViewJavascriptBridge(function(bridge) {
        js = bridge;
		/*bridge.registerHandler('callJS', function(data, responseCallback) {
			document.getElementById('testID').innerHTML =  data.data
			responseCallback('js收到了');
		});
*/
		bridge.callHandler('getC', {"data":"赶紧给我数据"}, function(response) {
	        	document.getElementById('log').innerHTML = response;
	        });
	 
        bridge.registerHandler('cellJS',function(data, responseCallback) {
               document.getElementById('log').innerHTML = data.OBJC;
                               responseCallback("什么啊");
                            });
	});

    function login() {
        
        js.callHandler('getABC',{"JS":"什么鬼"}, function(response) {
            document.getElementById('buttons').innerHTML = response;
                       });
     
    }

	</script>


	<div id='buttons'>XXXXXXXX</div> <div id='log'>OOOOOOOOOO</div>
    <br>
    <button onclick="login()">JS 调 OC 代码</button>
</body></html>
